package com.hugesoft.jxgs.activity;

import java.io.File;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.hugesoft.jxgs.R;
import com.hugesoft.jxgs.activity.base.BaseActivity;
import com.hugesoft.jxgs.view.HandWriteView;
import com.hugesoft.utils.FileUtil;

public class SignatureActivity extends BaseActivity implements OnClickListener {
	public static String TAGSIGIMGPATH = "TAGSIGIMGPATH";
	private Button btnSave, btnDel, btnClear;
	HandWriteView hwView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activitysignature);
		
		((TextView) findViewById(R.id.titleTextView)).setText("签名");
		findViewById(R.id.backImg).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		
		btnSave = (Button) findViewById(R.id.btnSave);
		btnSave.setOnClickListener(this);
		btnDel = (Button) findViewById(R.id.btnDel);
		btnDel.setOnClickListener(this);
		btnDel.setVisibility(View.GONE);
		btnClear = (Button) findViewById(R.id.btnClear);
		btnClear.setOnClickListener(this);

		hwView = (HandWriteView) findViewById(R.id.handWriteView1);

	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.btnClear:
			hwView.clear();
			break;
		case R.id.btnSave:
			File dir = new File(Environment.getExternalStorageDirectory()
					+ "/hugesoft/jxgs/signature");
			if (!dir.exists()) {
				dir.mkdirs();
			}
			String path = FileUtil.saveBitmapToSdCard(hwView.getCachebBitmap(),
					Environment.getExternalStorageDirectory().getAbsolutePath()
							+ "/hugesoft/jxgs/signature");
			Intent i = new Intent();
			i.putExtra(TAGSIGIMGPATH,path);
			setResult(0,i);
			finish();
		default:
			break;
		}
	}

}
